export const useCountdown = (time: number, callback1?: () => void, callback2?: () => void) => {
    const countdownTime = ref(time);
    // 倒计时状态管理
    const { pause, resume, isActive } = useIntervalFn(() => {
        // 当倒计时还未结束时，减少剩余时间
        if (countdownTime.value > 0) {
            countdownTime.value--;
            callback1 && callback1()
        } else {
            // 倒计时结束时，停止倒计时
            pause();
            callback2 && callback2()
        }
    }, 1000); // 间隔时间设置为1秒

    // 开始倒计时
    const startCountdown = () => {
        countdownTime.value = time; // 重置倒计时时间
        resume(); // 开始倒计时
    };

    // 暂停倒计时
    const stopCountdown = () => {
        pause(); // 暂停倒计时
    };
    return {
        countdownTime,
        startCountdown,
        stopCountdown

    }
}

export function customMsg(className: string, msg: string) {
    const parentDom = document.getElementsByClassName(className)[0]
    const childDom = parentDom.querySelectorAll('p')[0]
    childDom.innerHTML = msg
}